<%- # the license inside this block applies to this file
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
<%# NOTE NOTE NOTE
    The newlines in this file are *load bearing*.  This file outputs
    Markdown, which is extremely sensitive to newlines.  You have got
    to have a newline after every attribute and property, because
    otherwise MD will think the next element is part of the previous
    property's bullet point.  You cannot have any double newlines in the
    middle of a property or attribute, because MD will think that the
    empty line ends the bullet point and the indentation will be off.
    You must have a newline before and after all --- document indicators,
    and you must have a newline before and after all - - - hlines.
    You cannot have more than one blank line between properties.
    The --- document indicator must be the first line of the file.
    As long as you only use `build_property_documentation`, it all works
    fine - but when you need to add custom docs (notes, etc), you need
    to remember these things.

    Know also that the `lines` function in heavy use in MagicModules will
    strip exactly one trailing newline - unless that's what you've designed
    your docstring for, it's easier to insert newlines where you need them
    manually.  That's why, in this file, we use `lines` on anything which
    is generated from a ruby function, but skip it on anything that is
    directly inserted from YAML.
-%>
<%
  tf_product = (@config.legacy_name || product_ns).underscore
  tf_subcategory = (object.__product.display_name)
  terraform_name = object.legacy_name || "google_#{tf_product}_#{object.name.underscore}"
  properties = object.all_user_properties
  sensitive_props = object.all_nested_properties(object.root_properties).select(&:sensitive)
  # In order of preference, use TF override,
  # general defined timeouts, or default Timeouts
  timeouts = object.timeouts
  timeouts ||= object&.async&.operation&.timeouts
  timeouts ||= Api::Timeouts.new
-%>
---
<%= lines(autogen_notice(:yaml, pwd)) -%>
subcategory: "<%= tf_subcategory -%>"
layout: "google"
page_title: "Google: <%= terraform_name -%>"
sidebar_current: "docs-<%= terraform_name.gsub("_", "-") -%>"
description: |-
<%= indent(object.description.first_sentence, 2) %>
---

# <%= terraform_name.gsub("_", "\\_") %>

<%= lines(object.description) -%>

<% if object.min_version.name == 'beta' -%>
~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources.
<% end -%>

<% if !object.references.nil? -%>
To get more information about <%= object.name -%>, see:

<%   if !object.references.api.nil? -%>
* [API documentation](<%= object.references.api -%>)
<%   end # object...api.nil? -%>
<%   if !object.references.guides.empty? -%>
* How-to Guides
<%     object.references.guides.each do |title, link| -%>
    * [<%= title -%>](<%= link -%>)
<%     end # object...guides.each -%>
<%   end # object...guides.empty? -%>
<% end # object...api.nil? -%>
<%- unless object.docs.warning.nil? -%>

~> **Warning:** <%= object.docs.warning -%>
<%- end -%>
<%- unless object.docs.note.nil? -%>

~> **Note:** <%= object.docs.note -%>
<%- end -%>
<%- if !sensitive_props.empty? -%>
<%-
  sense_props = sensitive_props.map! {|prop| "`"+prop.lineage+"`"}.to_sentence
-%>

~> **Warning:** All arguments including <%= sense_props -%> will be stored in the raw
state as plain-text. [Read more about sensitive data in state](/docs/state/sensitive-data.html).
<%- end -%>

<%#- We over-generate examples/oics buttons here; they'll all be _valid_ just not necessarily intended for this provider version.
     Unless/Until we split our docs, this is a non-issue. -%>
<% unless object.examples.empty? -%>
  <%- object.examples.reject(&:skip_docs).each do |example| -%>
    <%- unless example.skip_test || (!example.test_env_vars.nil? && example.test_env_vars.any?)  -%>
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
  <a href="<%= example.oics_link %>" target="_blank">
    <img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
  </a>
</div>
    <%- end -%>
## Example Usage - <%= example.name.camelize(:upper).titleize %>


<%= example.config_documentation(pwd) -%>
  <%- end %>
<%- end -%>
## Argument Reference

The following arguments are supported:

<% object.root_properties.select(&:required).each do |prop| -%>
<%= lines(build_property_documentation(prop, pwd)) -%>
<% end -%>

<% properties.select(&:required).each do |prop| -%>
<%= lines(build_nested_property_documentation(prop, pwd)) -%>
<% end -%>
<%- unless object.docs.required_properties.nil? -%>
<%= "\n" + object.docs.required_properties -%>
<% end -%>

- - -

<% object.root_properties.reject(&:required).reject(&:output).each do |prop| -%>
<%=    lines(build_property_documentation(prop, pwd)) -%>
<% end -%>
<% if object.base_url.include?("{{project}}") || (object.create_url && object.create_url.include?('{{project}}'))-%>
<%# The following new line allow for project to be bullet-formatted properly. -%>

* `project` - (Optional) The ID of the project in which the resource belongs.
    If it is not provided, the provider project is used.
<% end -%>

<%- unless object.virtual_fields.empty? -%>
<%-   object.virtual_fields.each do |field| -%>
* `<%= field.name -%>` - (Optional) <%= field.description -%>

<%    end -%>
<% end -%>
<%- unless object.docs.optional_properties.nil? -%>
<%= object.docs.optional_properties -%>
<% end -%>
<% properties.reject(&:required).reject(&:output).each do |prop| -%>
<%= lines(build_nested_property_documentation(prop, pwd)) -%>
<% end -%>

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

* `id` - an identifier for the resource with format `<%= id_format(object) %>`
<% object.root_properties.select(&:output).each do |prop| -%>
<%= lines(build_property_documentation(prop, pwd)) -%>
<% end -%>
<% if object.has_self_link -%>
* `self_link` - The URI of the created resource.
<% end -%>

<% properties.select(&:output).each do |prop| -%>
<%= lines(build_nested_property_documentation(prop, pwd)) -%>
<% end -%>
<%- unless object.docs.attributes.nil? -%>
<%= "\n" + object.docs.attributes -%>
<% end -%>

## Timeouts

This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is <%= timeouts.insert_minutes -%> minutes.
<% if updatable?(object, properties) -%>
- `update` - Default is <%= timeouts.update_minutes -%> minutes.
<% end -%>
- `delete` - Default is <%= timeouts.delete_minutes -%> minutes.

## Import
<% if object.exclude_import -%>

This resource does not support import.

<% else %>

<%= object.name -%> can be imported using any of these accepted formats:

```
<% import_id_formats_from_resource(object).map{ |id| id.gsub('%', '') }.each do |id_format| -%>
$ terraform import <%= terraform_name -%>.default <%= id_format %>
<% end -%>
```

<% end -%>
<% if object.base_url.include?("{{project}}") || object.supports_indirect_user_project_override -%>
## User Project Overrides

This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).
<% end -%>
